package com.example.day2.zhibo;

import androidx.lifecycle.MutableLiveData;

import com.example.day2.entity.StartParam;
import com.example.day2.entity.StartResult;
import com.example.day2.entity.StopResult;
import com.example.day2.mvvm.base.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class StartRepo extends BaseRepo {
    public void getStart(StartParam startParam, MutableLiveData<StartResult> success,MutableLiveData<String> fail){
        apiService.getStart(startParam)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StartResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StartResult startResult) {
                        success.setValue(startResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getStop(MutableLiveData<StopResult> success,MutableLiveData<String> fail){
        apiService.getStop()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StopResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StopResult stopResult) {
                        success.setValue(stopResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
